package com.isoft.service.tableservice;

import com.isoft.dao.tabledao.DfmeGtlsDao;
import com.isoft.entity.tableentity.dfme_gtls.DfmeGtlsGate;
import com.isoft.entity.tableentity.dfme_gtls.DfmeGtlsMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
@Slf4j
public class DfmeGtlsService {
    @Autowired
    DfmeGtlsDao dfmeGtlsDao;
    public int insertmsg(DfmeGtlsMsg dfmeGtlsMsg) throws Exception{
        Timestamp create_time = new Timestamp(System.currentTimeMillis());
        dfmeGtlsDao.insertMeta(create_time,dfmeGtlsMsg.getDfmeGtlsMeta());
        dfmeGtlsDao.insertDflt(dfmeGtlsMsg.getDfmeGtlsMeta().getSeqn(),create_time,dfmeGtlsMsg.getDfmeGtlsDflt());
        List<DfmeGtlsGate> gateList  = dfmeGtlsMsg.getDfmeGtlsDflt().getGateList();
        if (gateList != null&&! gateList.isEmpty()){
            for (int i = 0; i < gateList.size(); i++) {
                DfmeGtlsGate dfmeGtlsGate = gateList.get(i);
                return dfmeGtlsDao.insertGate(dfmeGtlsMsg.getDfmeGtlsMeta().getSeqn(),create_time,dfmeGtlsGate);
            }
        }
       return 1;
    }
}
